﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace BTL
{
    public partial class xoauser : Form
    {
        BAL.userBAL _user;
        public xoauser()
        {
            InitializeComponent();
            
        }
        private void databind()
        {
            box_ten.DataBindings.Clear();
            box_ten.DataBindings.Add("text",dataGridViewSach.DataSource,"ID");
        }
        private void bt_hienthi_Click(object sender, EventArgs e)
        {
            try
            {
                _user = new BAL.userBAL();
                dataGridViewSach .DataSource = _user.xem();
            }
            catch
            {
                MessageBox.Show("Lỗi", "Xem help để nhận giúp đỡ", MessageBoxButtons.OK);
            }
            
        }

        private void bt_xoa_Click(object sender, EventArgs e)
        {
            try
            {
                _user = new BAL.userBAL();
                dataGridViewSach.DataSource = _user.xoa(box_ten.Text);
            }
            catch
            {
                MessageBox.Show("Lỗi","Xem help để nhận giúp đỡ",MessageBoxButtons.OK);
            }
            
        }

        private void bt_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                SqlConnection conn = new SqlConnection(Core.Connectionstring.Con.ToString());
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from tblUser where ID like '%" + box_tk.Text.Trim() + "%'";
                cmd.ExecuteNonQuery();
                da.Fill(dt);
                dataGridViewSach.DataSource = dt;
                conn.Close();
                databind();
            }
            catch
            {
                MessageBox.Show("Lỗi", "Xem help để nhận giúp đỡ", MessageBoxButtons.OK);
            }
            
        }

        private void xoauser_Load(object sender, EventArgs e)
        {
            bt_hienthi_Click(sender, e);
            databind();
        }


    }
}
